package dahuiji.admin.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.sun.jmx.snmp.tasks.Task;

import dahuiji.common.core.TaskJob;
import dahuiji.common.entity.User;
import dahuiji.common.servlet.BaceServlet;
import dahuiji.common.util.Constants;
import dahuiji.common.util.EncodingFormat;
import dahuiji.regist.service.RegistService;

public class TurnOff extends BaceServlet {

	/**
	 * Constructor of the object.
	 */
	public TurnOff() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * Initialization of the servlet. <br>
	 * 
	 * @throws ServletException
	 *             if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

	@Override
	public String perform(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String result = null;// 注册失败后的提示
		String nextPage = null;// 跳转页面
		RequestDispatcher rd;
		
		nextPage = "/view/admin/MyJsp.jsp";// 注册后跳转到首页
		if(TaskJob.getInstance().isAlive()){
			result = "关闭检测";
			TaskJob.gate = Constants.TURN_OFF;// 关闭开关
			TaskJob.getInstance().stop();// 得到单利线程，并关闭线程
			
		}else{
			result = "系统还没启动无法关闭";
		}
		request.setAttribute("msg", result);
		rd = getServletContext().getRequestDispatcher(nextPage);
		rd.forward(request, response);

		return nextPage;
	}

}
